const Base = require('../base.js');

module.exports = class extends Base {
  /**
   * @api {get} /leavelist 获取机构列表
   * @apiName SearchUser
   * @apiGroup userinfo
   *
   * @apiSuccess {Number} id 机构id
   *
   * @apiSuccess {String} name 机构名称
   *
   * @apiSuccessExample Success-Response:
   *     HTTP/1.1 200 OK
   *     [{
   *       "id": 2,
   *       "name": "西安研发中心"
   *     }]
   *
   */
  async getAction() {
    try {
      const id = this.get('id');
      const type = this.get('type');
      const leave = think.model('vacate', 'mysqlLocal');
      const leaveList = await leave.where({ user_id: id, type }).field('type, applytime, starttime, endtime, duration, reason').select();
      this.body = leaveList;
    } catch (error) {
      this.fail('502');
      think.logger.debug(error);
    }
  }
};
